<?php
/**
 * DBShop 电子商务系统
 *
 * ==========================================================================
 * @link      https://www.dbshop.net/
 * @copyright 北京珑大钜商科技有限公司，并保留所有权利。
 * @license   https://www.dbshop.net/license.html License
 * ==========================================================================
 *
 * @author    静静的风 <baron@loongdom.cn>
 *
 */

namespace Sales\View;

use Admin\Data\Common;
use Laminas\Mvc\I18n\Translator;
use Laminas\View\Helper\AbstractHelper;
use Sales\Data\OrderState;
use Sales\Entity\Order;

class SalesHelper extends AbstractHelper
{
    private $translator;

    public function __construct(
        Translator  $translator
    )
    {
        $this->translator   = $translator;
    }

    /**
     * 订单状态
     * @param $orderStatus
     * @return mixed
     */
    public function getOrderStatus($orderStatus)
    {
        return Common::orderStatus($this->translator)[$orderStatus];
    }

    /**
     * 订单状态编码
     * @param $statusStr
     * @return mixed
     */
    public function getOrderStatusCode($statusStr)
    {
        return Common::orderStatusCode($statusStr);
    }

    /**
     * 订单支付类型名称
     * @param $typeCode
     * @return mixed
     */
    public function getPaymentTypeName($typeCode)
    {
        return Common::paymentTypeName($typeCode, $this->translator);
    }

    /**
     * 订单退款类型，包括售后退款
     * @param $returnType
     * @return mixed
     */
    public function getOrderRefundType($returnType)
    {
        return Common::orderRefundType($this->translator)[$returnType];
    }

    /**
     * 订单配送类型名称
     * @param $typeCode
     * @return mixed
     */
    public function getDeliveryTypeName($typeCode)
    {
        return Common::deliveryTypeName($typeCode, $this->translator);
    }

    /**
     * 退货退款类型
     * @param $returnType
     * @return mixed
     */
    public function getOrderGoodsReturnType($returnType)
    {
        return Common::orderGoodsReturnType($this->translator)[$returnType];
    }

    /**
     * 退款退货状态
     * @param $state
     * @return mixed
     */
    public function getOrderGoodsReturnState($state)
    {
        return Common::orderGoodsReturnState($this->translator)[$state];
    }

    /**
     * 退款支付方式
     * @param $type
     * @return mixed
     */
    public function getOrderGoodsReturnPayType($type)
    {
        return Common::goodsReturnPayTypeArray($this->translator)[$type];
    }

    /**
     * 取消订单，判断是否可以进行处理
     * @param Order $orderInfo
     * @return bool
     */
    public function cancelOrder(Order $orderInfo)
    {
        return OrderState::cancelOrder($orderInfo);
    }

    /**
     * 订单付款时，判断是否可以付款
     * @param Order $orderInfo
     * @return bool
     */
    public function payOrder(Order $orderInfo)
    {
        return OrderState::payOrder($orderInfo);
    }

    /**
     * 订单发货时，判断是否可以进行发货处理
     * @param Order $orderInfo
     * @return bool
     */
    public function shipOrder(Order $orderInfo)
    {
        return OrderState::shipOrder($orderInfo);
    }

    /**
     * 订单收货，判断是否可以进行收货操作
     * @param Order $orderInfo
     * @return bool
     */
    public function receiptOrder(Order $orderInfo)
    {
        return OrderState::receiptOrder($orderInfo);
    }

    /**
     * 判断是否可以修改订单快递单号
     * @param Order $orderInfo
     * @return bool
     */
    public function editOrderExpressNumber(Order $orderInfo)
    {
        return OrderState::editOrderExpressNumber($orderInfo);
    }

    /**
     * 物流轨迹，判断是否可查看物流轨迹
     * @param Order $orderInfo
     * @param array $deliveryIdArray
     * @return bool
     */
    public function orderExpressTrack(Order $orderInfo, array $deliveryIdArray = [])
    {
        return OrderState::orderExpressTrack($orderInfo, $deliveryIdArray);
    }
}